﻿using System;
using System.Net;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using System.Runtime.InteropServices;
using Styx;
using System.Threading;
using System.Linq;

using Styx.Common;

namespace rndbuddy
{
    static class FSUtil
    {
        public static FileInfo LatestFileInDir(string path)
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            if (dir == null || !dir.Exists)
                return null;

            FileInfo myFile = dir.GetFiles()
             .OrderByDescending(f => f.LastWriteTime)
             .First();

            return myFile;
        }

        public static Image GetImageFromURL(string url)
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
            HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
            Stream stream = httpWebReponse.GetResponseStream();
            return Image.FromStream(stream);
        }
    }
}
